package com.pagepub.expo.manager;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pagepub.expo.dao.CorpTemplateDao;
import com.pagepub.expo.entity.CorpCatalog;
import com.pagepub.expo.entity.CorpPublicationPage;
import com.pagepub.expo.entity.CorpTemplate;
import com.pagepub.expo.entity.IdName;

@Service
@Transactional
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class CorpTemplateMng {
	@Autowired
	private CorpTemplateDao corpTemplateDao;


	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpTemplate> findAll() {
		return corpTemplateDao.findAll();
	}
	

	@RemotingInclude
	public CorpTemplate findById(Long id) {
		return corpTemplateDao.findById(id);
	}
	


	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public int getCount(Map<String, String> param){
		return corpTemplateDao.getCount(param);
	}
	
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpTemplate> findByPage(int currentPage,int pageSize,Map<String, String> param){
		return corpTemplateDao.findByPage(currentPage, pageSize, param);
	}


	@RemotingInclude
	public CorpTemplate add(CorpTemplate corpTemplate) {
		corpTemplateDao.insert(corpTemplate);
		return corpTemplateDao.findById(new Long(corpTemplate.getId()));
	}

	@RemotingInclude
	public Long remove(Long id) {
		corpTemplateDao.delete(id);
		return id;
	}

	@RemotingInclude
	public CorpTemplate update(CorpTemplate corpTemplate) {
		corpTemplateDao.update(corpTemplate);
		return corpTemplateDao.findById(new Long(corpTemplate.getId()));
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<IdName> findIdNames(){
		return corpTemplateDao.findIdNames();
	}
}
